package com.sc.nft.admin.rpc;

import cn.hutool.extra.servlet.ServletUtil;
import com.sc.nft.admin.request.ApprovalRefundSuccessRequest;
import com.sc.nft.admin.request.RpcApprovalRefundRequest;
import com.sc.nft.service.MallOrderRefundService;
import com.sc.nft.service.MallOrderService;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/rpc/mall/refund")
@Api(tags = "后台商城售后RPC接口")
public class MallRefundRpc {

    private final MallOrderService mallOrderService;
    private final MallOrderRefundService mallOrderRefundService;

    @PostMapping(value = "/approvalRefundSuccess", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "审核售后成功并退钱", notes = "审核售后成功并退钱", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiIgnore
    public Result approvalRefundSuccess(@Valid @RequestBody ApprovalRefundSuccessRequest request, HttpServletRequest httpServletRequest) {
        mallOrderService.approvalRefundSuccess(request.getId(),request.getOrderProductId(),ServletUtil.getClientIP(httpServletRequest));
        return Result.success();
    }

    @PostMapping(value = "/approval", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "审核售后", notes = "审核售后", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiIgnore
    public Result approval(@RequestBody RpcApprovalRefundRequest request, HttpServletRequest httpServletRequest) {
        mallOrderRefundService.approvalRefund(request.getId(),request.getMallRefundStatus(),ServletUtil.getClientIP(httpServletRequest),request.getRefundReason(),request.getDeliveryName(),request.getDeliveryNo(), false);
        return Result.success();
    }

}
